﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="jq/picker/jquery-ui-1.10.3.custom.min.css" rel="stylesheet" />
    <script src="jq/picker/jquery-1.9.1.js"></script>
    <script src="jq/picker/jquery-ui-1.10.3.custom.min.js"></script>
    <script src="jq/picker/DatePickerCN.js"></script>
    <style type="text/css">
        body {
            font: 62.5% "Trebuchet MS", sans-serif;
        }
    </style>
</head>
<body>
    <div id="d1">
        <input type="text" id="txt1" />
        <select id="sel">
            <option>1</option>
            <option selected="selected">2</option>
        </select>
        <input type="text" id="Text1" />
        <select id="Select1">
            <option>1</option>
            <option selected="selected">2</option>
        </select>
        <input type="checkbox" id="chk" />
        <input type="radio" id="rad" />
        <input type="checkbox" id="Checkbox1" /> .

        <input type="radio" id="Radio1" />
        <textarea id="tare"></textarea>
        <input type="button" id="btn1" value="disabled" />
        <input type="button" id="btn2" value="enabled" />
    </div>
</body>
</html>

<script type="text/javascript">
    String.prototype.replaceAll = function (oldVal, newVal) {
        return this.replace(new RegExp(oldVal, "gm"), newVal);
    }

    var s = "123";

    //document.getElementById("txt1").onpropertychange = function () {
    //    alert(1);
    //}

    $("#txt1").bind("change", function () {
        //alert(1);
    })
    //document.getElementById("txt1").addEventListener("propertychange", function () {
    //    alert(1)
    //},true)


    function tagName(obj) {
        alert($(obj).get(0).tagName + "--" + $(obj).get(0).type);
    }
    //INPUT  text  
    //SELECT   select-one
    //INPUT    radio
    //INPUT    button
    //TEXTAREA  textarea

    //tagName($("#tare"));

    Array.prototype.delete = function (dx) {
        if (isNaN(dx) || dx > this.length) { return false; }
        this.splice(dx, 1);
    }

    var Disabled = function () {
        this.disabledArr = [
            { tagName: "INPUT", type: "text" },
            { tagName: "SELECT", type: "select-one" },
            { tagName: "INPUT", type: "radio" },
            { tagName: "TEXTAREA", type: "textarea" },
            { tagName: "INPUT", type: "checkbox" },
            { tagName: "INPUT", type: "button" }
        ];
        this.enabledArr = [
            { tagName: "INPUT", type: "button" }
        ];

        this.AppendDisabledArr = function (json) {
            this.disabledArr(json);
        }

        this.AppendEnabledArr = function (json) {
            this.enabledArr.push(json);
        }

        this.RemoveItem = function () {
            var index = "";
            for (var i = 0; i < this.disabledArr.length; i++) {
                for (var j = 0; j < this.enabledArr.length; j++) {
                    if (this.disabledArr[i].tagName == this.enabledArr[j].tagName && this.disabledArr[i].type == this.enabledArr[j].type) {
                        index += i + ",";
                    }
                }
            }
            var delArr = index.substring(0, index.lastIndexOf(',')).split(',');

            var newDisabled = new Array();

            for (var i = 0; i < this.disabledArr.length; i++) {
                newDisabled.push(this.disabledArr[i]);
            }

            for (var i = delArr.length - 1; i >= 0; i--) {
                newDisabled.delete(delArr[i]);
            }
            return newDisabled;
        }

        this.DisabledAll = function (containerId) {
            if (containerId == "") {
                return;
            }
            var newItem = this.RemoveItem();
            for (var i = 0; i < newItem.length; i++) {
                if (newItem[i].tagName == "INPUT") {
                    $("#" + containerId + " " + newItem[i].tagName + "[type=" + newItem[i].type + "]").attr("disabled", "disabled");
                }
                else {
                    $("#" + containerId + " " + this.disabledArr[i].tagName).attr("disabled", "disabled");
                }
            }
        }

        this.EnabledAll = function (containerId) {
            if (containerId == "") {
                return;
            }
            var newItem = this.RemoveItem();
            for (var i = 0; i < newItem.length; i++) {
                if (newItem[i].tagName == "INPUT") {
                    $("#" + containerId + " " + newItem[i].tagName + "[type=" + newItem[i].type + "]").removeAttr("disabled");
                }
                else {
                    $("#" + containerId + " " + this.disabledArr[i].tagName).removeAttr("disabled");
                }
            }
        }
    }

    var d = new Disabled();
    $("#btn1").click(function () {
        d.DisabledAll("d1");
    })
    $("#btn2").click(function () {
        d.EnabledAll("d1");
    })

    $("#txt1").datepicker();
</script>
